package com.competition.web.admin.task.run;

import java.util.List;

import org.springframework.core.ParameterizedTypeReference;
import org.springframework.data.redis.core.ListOperations;
import org.springframework.data.redis.core.RedisTemplate;

import com.admin.param.contract.IOrganizeRequestParam;
import com.competition.param.impl.OrganizeRequestParam;
import com.competition.web.admin.config.HttpRequest;
import com.competition.web.constant.RedisConstant;
import com.unify.type.Department;
import com.unify.type.ExploringHorsesResponse;

public class ObtainingTanmaElectricInvitationData implements Runnable {

	private HttpRequest httpRequest;
	
	private RedisTemplate<String, Department> redisTemplate;
	
	public ObtainingTanmaElectricInvitationData(HttpRequest httpRequest, RedisTemplate<String, Department> redisTemplate) {
		
		this.httpRequest = httpRequest;
		
		this.redisTemplate = redisTemplate;
		
	}
	
	@Override
	public void run() {
		
		ParameterizedTypeReference<ExploringHorsesResponse<List<Department>>> parameterizedTypeReference = new ParameterizedTypeReference<ExploringHorsesResponse<List<Department>>>() {
		};
		
		IOrganizeRequestParam organizeRequestParam = new OrganizeRequestParam();
		
		// 398290 <-------> 电邀部
		organizeRequestParam.setId(398290);
		
		ExploringHorsesResponse<List<Department>> exploringHorsesResponse = this.httpRequest.geOrganize(organizeRequestParam, parameterizedTypeReference);
		
		if (0 != exploringHorsesResponse.getCode()) {
			return;
		}
		
		List<Department> data = exploringHorsesResponse.getData();
		
		ListOperations<String, Department> opsForList = this.redisTemplate.opsForList();
		
		for (Department department : data) {
			opsForList.rightPush(RedisConstant.INVITATION_DEPARTMENT, department);
		}
	}

}
